package com.cqc.crm.action;

import org.hibernate.criterion.DetachedCriteria;

import com.cqc.crm.domain.Customer;
import com.cqc.crm.service.CustomerService;
import com.cqc.crm.utils.PageBean;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.util.ValueStack;

public class CustomerAction extends ActionSupport implements ModelDriven<Customer> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9176812910048769004L;
	private Customer customer = new Customer();
	@Override
	public Customer getModel() {
		return customer;
	}
	
	//设置默认值   当前页码
	private Integer pageCode=1;
	public void setPageCode(Integer pageCode) {
		this.pageCode = pageCode;
	}
	//一页显示多少条数据
	private Integer pageSize=2;
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	private CustomerService customerService;
	public void setCustomerService(CustomerService customerService) {
		this.customerService = customerService;
	}


	/**
	 * 分页查找，调转到list.jsp
	 * @return
	 */
	public String findByPage() {
		DetachedCriteria criteria = DetachedCriteria.forClass(Customer.class);
		PageBean<Customer> pageBean=customerService.findByPage(pageCode,pageSize,criteria);
		
		ValueStack vs = ActionContext.getContext().getValueStack();
		vs.push(pageBean);
		return "list";
	}

}
